home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / storage / lmgr / single.c < prev   
Encoding:
C/C++ Source or Header  |  1992-08-27  |  2.9 KB  |  112 lines

  1. /*
  2.  * single.c -- set single locks in the multi-level lock 
  3.  *    hierarchy.
  4.  *
  5.  * Sometimes we don't want to set all levels of the multi-level
  6.  *    lock hierarchy at once.  This allows us to set and release
  7.  *     one level at a time.  It's useful in index scans when
  8.  *    you can set an intent lock at the beginning and thereafter
  9.  *     only set page locks.  Tends to speed things up.
  10.  *
  11.  * $Header: /private/postgres/src/storage/lmgr/RCS/single.c,v 1.1 1991/10/29 20:26:11 mer Exp $
  12.  */
  13. #include "storage/lmgr.h"
  14. #include "storage/lock.h"
  15. #include "storage/multilev.h"
  16. #include "utils/rel.h"
  17.  
  18. /* from multi.c */
  19. extern LockTableId MultiTableId;
  20.  
  21. /*
  22.  * SingleLockReln -- lock a relation
  23.  *
  24.  * Returns: TRUE if the lock can be set, FALSE otherwise.
  25.  */
  26. SingleLockReln(linfo, lockt, action)
  27.     LockInfo     linfo;
  28.     LOCKT    lockt;
  29.     int        action;
  30. {
  31.     LOCKTAG    tag;
  32.  
  33.     /* 
  34.      * LOCKTAG has two bytes of padding, unfortunately.  The
  35.      * hash function will return miss if the padding bytes aren't
  36.      * zero'd.
  37.      */
  38.     bzero(&tag,sizeof(tag));
  39.     tag.relId = linfo->lRelId.relId;
  40.     tag.dbId = linfo->lRelId.dbId;
  41.     BlockIdSet(ItemPointerBlockId(&tag.tupleId), InvalidBlockNumber);
  42.     PositionIdSetInvalid( ItemPointerPositionId(&(tag.tupleId)) );
  43.  
  44.     if (action == UNLOCK)
  45.     return(LockRelease(MultiTableId, &tag, lockt));
  46.     else
  47.     return(LockAcquire(MultiTableId, &tag, lockt));
  48. }
  49.  
  50. /*
  51.  * SingleLockPage -- use multi-level lock table, but lock
  52.  *    only at the page level.
  53.  *
  54.  * Assumes that an INTENT lock has already been set in the
  55.  * multi-level lock table.
  56.  *
  57.  */
  58. SingleLockPage(linfo, tidPtr, lockt, action)
  59. LockInfo     linfo;
  60. ItemPointer    tidPtr;
  61. LOCKT        lockt;
  62. int        action;
  63. {
  64.     LOCKTAG    tag;
  65.  
  66.     /* 
  67.      * LOCKTAG has two bytes of padding, unfortunately.  The
  68.      * hash function will return miss if the padding bytes aren't
  69.      * zero'd.
  70.      */
  71.     bzero(&tag,sizeof(tag));
  72.     tag.relId = linfo->lRelId.relId;
  73.     tag.dbId = linfo->lRelId.dbId;
  74.     BlockIdCopy( ItemPointerBlockId(&tag.tupleId), ItemPointerBlockId(tidPtr) );
  75.     PositionIdSetInvalid( ItemPointerPositionId(&(tag.tupleId)) );
  76.  
  77.  
  78.     if (action == UNLOCK)
  79.     return(LockRelease(MultiTableId, &tag, lockt));
  80.     else
  81.     return(LockAcquire(MultiTableId, &tag, lockt));
  82. }
  83.  
  84. /*
  85.  * SingleLockTuple -- use the multi-level lock table,
  86.  *    but lock only at the tuple level.
  87.  *
  88.  * XXX not used and not tested --mer 28 Oct 1991
  89.  */
  90. SingleLockTuple(linfo, tidPtr, lockt, action)
  91. LockInfo    linfo;
  92. ItemPointer    tidPtr;
  93. LOCKT        lockt;
  94. int        action;
  95. {
  96.     LOCKTAG    tag;
  97.  
  98.     /* LOCKTAG has two bytes of padding, unfortunately.  The
  99.      * hash function will return miss if the padding bytes aren't
  100.      * zero'd.
  101.      */
  102.     bzero(&tag,sizeof(tag));
  103.     tag.relId = linfo->lRelId.relId;
  104.     tag.dbId = linfo->lRelId.dbId;
  105.     tag.tupleId = *tidPtr;
  106.  
  107.     if (action == UNLOCK)
  108.     return(LockRelease(MultiTableId, &tag, lockt));
  109.     else
  110.     return(LockAcquire(MultiTableId, &tag, lockt));
  111. }
  112.